//
//  AllViewController.m
//  HandheldHospital
//
//  Created by lanou3g on 16/2/29.
//  Copyright © 2016年 zhangchao. All rights reserved.
//

#import "AllViewController.h"
#import <DOPDropDownMenu.h>
@interface AllViewController ()<DOPDropDownMenuDataSource,DOPDropDownMenuDelegate>

@property (nonatomic, strong) NSArray *classifys;
@property (nonatomic, strong) NSArray *cates;
@property (nonatomic, strong) NSArray *movices;
@property (nonatomic, strong) NSArray *hostels;
@property (nonatomic, strong) NSArray *areas;

@property (nonatomic, strong) NSArray *sorts;
@property (nonatomic, weak) DOPDropDownMenu *menu;



@end

@implementation AllViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self addDOropDownMenu];
}

- (void)addDOropDownMenu
{
    
    self.title = @"所有医院";
    self.view.backgroundColor = [UIColor whiteColor];
    
    //隐藏tabBar
    self.tabBarController.tabBar.hidden = YES;
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"重置" style:UIBarButtonItemStylePlain target:self action:@selector(menuReloadData)];
    // 数据
    self.classifys = @[@"医院",@"优惠活动",@"医院主治",@"医院等级"];
    self.cates = @[@"医学科学院北京协和医院",@"中国医学科学院肿瘤医院",@"医科大附属北京儿童医院",@"首都医科大学原宣武医院",@"医科大附属北京朝阳医院",@"中日友好医院",@"北京老年医院",@"北京军区医院",@"北京京煤集团总医院",@"中国解放军总总医院",@"北京医院",@"北京妇产科医院",@"北京同仁医院",@"山西阳光男科医院",@"济南蓝翔肛肠医院",@"北京世纪坛医院",@"辽宁天堂医院",@"山西儿童医院",@"山西医科大学第一医院",@"上海长海医院",@"第三人民医院",@"京城皮肤病医院",@"北京中医医院",@"上海中山医院",@"复旦大学附属肿瘤医院",@"季世堂医院"];
    self.movices = @[@"肛肠医院",@"肿瘤医院",@"儿童医院",@"妇产科医院",@"牙科医院",@"胸科医院",@"骨科医院"];
    
    self.hostels = @[@"一级甲等",@"一级乙等",@"二级甲等",@"二级乙等",@"三级甲等",@"三级乙等"];
    
    self.areas = @[@"全城",@"东城区",@"西城区",@"宣武区",@"丰台区",@"石景山区",@"海淀区",@"房山区",@"通州区",@"义顺区",@"昌平区",@"大兴区",@"平谷区",@"怀柔区",@"朝阳区"];
    
    self.sorts = @[@"默认排序",@"离我最近",@"好评优先",@"人气优先",@"医院等级"];
    
    // 添加下拉菜单
    DOPDropDownMenu *menu = [[DOPDropDownMenu alloc] initWithOrigin:CGPointMake(0, 64) andHeight:44];
    menu.delegate = self;
    menu.dataSource = self;
    [self.view addSubview:menu];
    _menu = menu;
    [menu selectDefalutIndexPath];
}

- (void)menuReloadData
{
    self.classifys = @[@"医院",@"活动优惠",@"医院主治"];
    [_menu reloadData];
}

- (NSInteger)numberOfColumnsInMenu:(DOPDropDownMenu *)menu
{
    return 3;
}

- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column
{
    if (column == 0) {
        return self.classifys.count;
    }else if (column == 1){
        return self.areas.count;
    }else {
        return self.sorts.count;
    }
}

- (NSString *)menu:(DOPDropDownMenu *)menu titleForRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0) {
        return self.classifys[indexPath.row];
    } else if (indexPath.column == 1){
        return self.areas[indexPath.row];
    } else {
        return self.sorts[indexPath.row];
    }
}

- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfItemsInRow:(NSInteger)row column:(NSInteger)column
{
    if (column == 0) {
        if (row == 0) {
            return self.cates.count;
        } else if (row == 2){
            return self.movices.count;
        } else if (row == 3){
            return self.hostels.count;
        }
    }
    return 0;
}

- (NSString *)menu:(DOPDropDownMenu *)menu titleForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0) {
        if (indexPath.row == 0) {
            return self.cates[indexPath.item];
        } else if (indexPath.row == 2){
            return self.movices[indexPath.item];
        } else if (indexPath.row == 3){
            return self.hostels[indexPath.item];
        }
    }
    return nil;
}

- (void)menu:(DOPDropDownMenu *)menu didSelectRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.item >= 0) {
        NSLog(@"点击了 %ld - %ld - %ld 项目",indexPath.column,indexPath.row,indexPath.item);
    }else {
        NSLog(@"点击了 %ld - %ld 项目",indexPath.column,indexPath.row);
    }
}

    


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
